package com.qf.common.core.common;

import com.qf.common.core.constant.CommonConstant;

/**
 * --- 永无霸哥 ---
 *
 * @author M.rk
 * @date 2024/11/12 15:52
 * @desc 这个类用于前后端交互时 返回给前端封装json使用
 *
 */

public class R {
    private int code;
    private String msg;
    private Object data;

    public static R ok(){
        R r = new R();
        r.setCode(CommonConstant.SUCCESS);
        r.setMsg("成功");
        return  r;
    }



    public static R ok(int code,String msg ){
        R r = new R();
        r.setCode(CommonConstant.SUCCESS);
        r.setMsg(msg);
        return  r;
    }


 public static R ok(String msg ){
        R r = new R();
        r.setCode(CommonConstant.SUCCESS);
        r.setMsg(msg);
        return  r;
    }

    public static R ok(Object data ){
        R r = new R();
        r.setCode(CommonConstant.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return  r;
    }



    // public static R ok(int code, String msg, Object data) {
    //     R r = new R();
    //     r.setCode(CommonConstant.SUCCESS); ;
    //     r.setMsg(msg);
    //     r.setData(data);
    //     return r;
    // }

    public static R fail( ){
        R r = new R();
        r.setCode(CommonConstant.ERROR);
        r.setMsg("失败");
        return  r;
    }

    public static R fail(String msg ){
        R r = new R();
        r.setCode(CommonConstant.ERROR);
        r.setMsg(msg);
        return  r;
    }


    public static R fail(int code, String msg, Object data) {
        R r = new R();
        r.setCode(CommonConstant.ERROR); ;
        r.setMsg(msg);
        r.setData(data);
        return r;
    }




    public R() {
    }

    public static R fail(int code, String msg) {
        R r = new R();
        r.setCode(CommonConstant.ERROR);
        r.setMsg(msg);
        return r;


    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
